package top.hkyzf.study.leetcode.array;

import org.junit.Test;

import java.util.Arrays;

/**
 * @author 朱峰
 * @date 2022-1-28 9:15
 */
public class 游戏中弱角色的数量_1996 {
    public int numberOfWeakCharacters(int[][] properties) {
        // 第一维降序，第二维升序
        Arrays.sort(properties, (o1, o2) -> {
            if (o1[0] - o2[0] == 0) {
                return o1[1] - o2[1];
            } else {
                return o2[0] -o1[0];
            }
        });

        int temp = 0;
        int result = 0;
        for (int[] ints : properties) {
            if (ints[1] < temp) {
                result++;
            } else {
                temp = ints[1];
            }
        }
        return result;
    }

    @Test
    public void testNumberOfWeakCharacters () {
        int[][] properties = {{5,5},{6,3},{3,6},{5,4},{5,3},{5,2}};
        System.out.println(numberOfWeakCharacters(properties));
    }
}
